package trading.algo.BearTask;

import java.util.TimerTask;

import trading.algo.MasterAlgo;
import trading.bo.DBAccessorBO;
import trading.bo.EmailAccessorBO;
import trading.dataentry.MonitoredStocks;

public class MarketHourTask extends TimerTask {

	private DBAccessorBO dbAccessorBO;
	private MasterAlgo masterAlgo;
	private EmailAccessorBO emailAccessorBO;
	
	public MarketHourTask(DBAccessorBO dbAccessorBO, MasterAlgo masterAlgo, EmailAccessorBO emailAccessorBO) {
		this.dbAccessorBO = dbAccessorBO;
		this.masterAlgo = masterAlgo;
		this.emailAccessorBO = emailAccessorBO;
	}
	
	@Override
	public void run() {
		MonitoredStocks monitoredStock = this.dbAccessorBO.getMonitoredStockData(MonitoredStocks.TICKERS.UVXY.name());
		double lastPrice = monitoredStock.getLastPrice();
		double historicalLowPrice = monitoredStock.getHistoricalLow();
		if (lastPrice < historicalLowPrice) {
			this.masterAlgo.fromBearToBearToBull();
			this.emailAccessorBO.sendNewHistoricalLowEmail(MonitoredStocks.TICKERS.UVXY.name(), lastPrice + "");
		}
		
	}

}
